
#include "FileSect.h"
#include "FilePackage.h"

int CFileSect::writeData()
{
	if( m_pOwner )
	{
		FILE *stream;
		if( (stream = fopen( m_sInfo.m_szFileName, "rb+" )) != NULL )
		{
			char *buf = new char[m_sInfo.m_nDataLen];
			/* Attempt to read in 25 characters */
			int numread = (int)fread( buf, sizeof( char ), m_sInfo.m_nDataLen, stream );
			fclose( stream );
			m_pOwner->_writeData( m_sInfo.m_nOffset, m_sInfo.m_nDataLen, buf );
			delete[] buf;
			return m_sInfo.m_nDataLen;
		}
		return 0;

	}
	return 0;
}

int CFileSect::readData( char * buf )
{
	if( m_pOwner )
	{
		m_pOwner->_readData( m_sInfo.m_nOffset, m_sInfo.m_nDataLen, buf );
		return m_sInfo.m_nDataLen;
	}
	return 0;
}

int CFileSect::writeInfo()
{
	if( m_pOwner )
	{
		int _size = sizeof( SFileSectInfo);
		m_pOwner->__write( (char*)&m_sInfo, _size );
		return _size;
	}
	return 0;

}

int CFileSect::readInfo()
{
	if( m_pOwner )
	{
		int _size = sizeof( SFileSectInfo);
		m_pOwner->__read( (char*)&m_sInfo, _size );
		return _size;
	}
	return 0;

}